#include<iostream>
#include<vector>

using namespace std;

vector<int> v[10005];
int main(void) {
	int n, m, a, b;
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		v[i].push_back(i);
	}
	for(int i = 1; i <= m; i++) {
		cin >> a >> b;
		if(a == b) {
			continue;
		} else {
			for(int j = 0; j < v[b].size(); j++) {
				v[a].push_back(v[b][j]);
			}
			vector<int>().swap(v[b]);
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < v[i].size(); j++) {
			cout << v[i][j] << ends;
		}
		cout << endl;
	}
	return 0;
}
